/**
 * Created by oneminute on 7/17/14.
 */

var lz = require("../lib/utils/modules")();

exports.get = function (_req, _res, _opts, _callback) {
    var did = _req.query.nid;
    var demand = new lz.Demand({id: did});
    demand.load({method: "byId"}, function (_err, _demand) {
        if (_demand) {
            var user = new lz.User({id: demand.uid});
            user.load({method: "byId"}, function (_err, _user) {
                var obj = demand.getInfo(_user);
                obj.publisher = _user.name;
                obj.telephone = _user.phone;
                obj.location = _user.address;
                obj.lat = _user.lat;
                obj.lon = _user.lon;

                _callback(null, null, obj);
            });
        } else {
            lz.Logger.warn("/need: 用户请求的需求不存在。");
            _callback(lz.Config.errors.getError(lz.Config.errors.REQUEST_NO_DEMAND));
        }
    });
};
